package cn.wzptsoft.mall.handler;

import cn.wzptsoft.mall.pojo.result.Result;
import com.alibaba.fastjson.JSONObject;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.authentication.InternalAuthenticationServiceException;
import org.springframework.stereotype.Service;

import java.io.IOException;


@Slf4j
public class AccessDeniedHandler implements org.springframework.security.web.access.AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        log.info("用户无权限");
        response.setContentType("text/json;charset=utf-8");
        String json = JSONObject.toJSONString(Result.error(-1, "用户无权限"));

        response.getWriter().println(json);

    }
}
